package cn.xzqwjw.taskmanager.security;

import lombok.Getter;
import org.springframework.security.authentication.AbstractAuthenticationToken;

import java.util.Collections;

/**
 * @author rush
 */
public class TokenAdmin extends AbstractAuthenticationToken {

  private static final long serialVersionUID = 1L;

  /**
   * 用户名
   */
  private final Object principal;

  /**
   * 密码
   */
  private final Object credentials;

  /**
   * 验证码
   */
  @Getter
  private final String validateCode;

  /**
   * 是否记住我
   */
  private final Boolean isRememberMe;

  /**
   * 登录时内网ip地址
   */
  @Getter
  private final String ipInner;

  /**
   * 登录时外网ip地址
   */
  @Getter
  private final String ipOuter;

  /**
   * 此构造函数用在拦截器拦截登录请求的时候
   * 此时要获取用户将登录表单的数据传递过来以供验证区进行验证
   */
  public TokenAdmin(
      Object principal,
      Object credentials,
      String validateCode,
      Boolean isRememberMe,
      String ipInner,
      String ipOuter) {
    super(Collections.emptyList());
    this.principal = principal;
    this.credentials = credentials;
    this.validateCode = validateCode;
    this.isRememberMe = isRememberMe;
    this.ipInner = ipInner;
    this.ipOuter = ipOuter;
    this.setAuthenticated(false);
  }

  @Override
  public Object getPrincipal() {
    return this.principal;
  }

  @Override
  public Object getCredentials() {
    return this.credentials;
  }

}
